home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / vim / src / structs.h < prev    next >
C/C++ Source or Header  |  1995-03-09  |  14KB  |  472 lines

  1. /* vi:ts=4:sw=4
  2.  *
  3.  * VIM - Vi IMproved        by Bram Moolenaar
  4.  *
  5.  * Read the file "credits.txt" for a list of people who contributed.
  6.  * Read the file "uganda.txt" for copying and usage conditions.
  7.  */
  8.  
  9. /*
  10.  * This file contains various definitions of structures that are used by Vim
  11.  */
  12.  
  13. /*
  14.  * file position
  15.  */
  16.  
  17. typedef struct fpos        FPOS;
  18. /*
  19.  * there is something wrong in the SAS compiler that makes typedefs not
  20.  * valid in include files
  21.  */
  22. #ifdef SASC
  23. typedef long            linenr_t;
  24. typedef unsigned        colnr_t;
  25. typedef unsigned short    short_u;
  26. #endif
  27.  
  28. struct fpos
  29. {
  30.     linenr_t        lnum;            /* line number */
  31.     colnr_t         col;            /* column number */
  32. };
  33.  
  34. /*
  35.  * marks: positions in a file
  36.  * (a normal mark is a lnum/col pair, the same as a file position)
  37.  */
  38.  
  39. #define NMARKS            26            /* max. # of named marks */
  40. #define JUMPLISTSIZE    30            /* max. # of marks in jump list */
  41. #define TAGSTACKSIZE    20            /* max. # of tags in tag stack */
  42.  
  43. struct filemark
  44. {
  45.     FPOS            mark;            /* cursor position */
  46.     int                fnum;            /* file number */
  47. };
  48.  
  49. /*
  50.  * the taggy struct is used to store the information about a :tag command:
  51.  *    the tag name and the cursor position BEFORE the :tag command
  52.  */
  53. struct taggy
  54. {
  55.     char_u            *tagname;            /* tag name */
  56.     struct filemark fmark;                /* cursor position */
  57. };
  58.  
  59. /*
  60.  * line number list
  61.  */
  62.  
  63. /*
  64.  * Each window can have a different line number associated with a buffer.
  65.  * The window-pointer/line-number pairs are kept in the line number list.
  66.  * The list of line numbers is kept in most-recently-used order.
  67.  */
  68.  
  69. typedef struct window        WIN;
  70. typedef struct winlnum        WINLNUM;
  71.  
  72. struct winlnum
  73. {
  74.     WINLNUM        *wl_next;            /* next entry or NULL for last entry */
  75.     WINLNUM        *wl_prev;            /* previous entry or NULL for first entry */
  76.     WIN            *wl_win;            /* pointer to window that did set wl_lnum */
  77.     linenr_t     wl_lnum;            /* last cursor line in the file */
  78. };
  79.  
  80. /*
  81.  * stuctures used for undo
  82.  */
  83.  
  84. struct u_entry
  85. {
  86.     struct u_entry    *ue_next;    /* pointer to next entry in list */
  87.     linenr_t        ue_top;        /* number of line above undo block */
  88.     linenr_t        ue_bot;        /* number of line below undo block */
  89.     linenr_t        ue_lcount;    /* linecount when u_save called */
  90.     char_u            **ue_array;    /* array of lines in undo block */
  91.     long            ue_size;    /* number of lines in ue_array */
  92. };
  93.  
  94. struct u_header
  95. {
  96.     struct u_header    *uh_next;    /* pointer to next header in list */
  97.     struct u_header    *uh_prev;    /* pointer to previous header in list */
  98.     struct u_entry    *uh_entry;    /* pointer to first entry */
  99.     FPOS             uh_cursor;    /* cursor position before saving */
  100.     int                 uh_changed;/* b_changed flag before undo/after redo */
  101.     FPOS             uh_namedm[NMARKS];    /* marks before undo/after redo */
  102. };
  103.  
  104. /*
  105.  * stuctures used in undo.c
  106.  */
  107. #ifdef UNIX
  108. # define ALIGN_LONG        /* longword alignment and use filler byte */
  109. # define ALIGN_SIZE (sizeof(long))
  110. #else
  111. # define ALIGN_SIZE (sizeof(short))
  112. #endif
  113.  
  114. #define ALIGN_MASK (ALIGN_SIZE - 1)
  115.  
  116. typedef struct m_info info_t;
  117.  
  118. /*
  119.  * stucture used to link chunks in one of the free chunk lists.
  120.  */
  121. struct m_info
  122. {
  123. #ifdef ALIGN_LONG
  124.     long_u     m_size;    /* size of the chunk (including m_info) */
  125. #else
  126.     short_u  m_size;    /* size of the chunk (including m_info) */
  127. #endif
  128.     info_t    *m_next;    /* pointer to next free chunk in the list */
  129. };
  130.  
  131. /*
  132.  * structure used to link blocks in the list of allocated blocks.
  133.  */
  134. struct m_block
  135. {
  136.     struct m_block    *mb_next;    /* pointer to next allocated block */
  137.     info_t            mb_info;    /* head of free chuck list for this block */
  138. };
  139.  
  140. /*
  141.  * things used in memfile.c
  142.  */
  143.  
  144. typedef struct block_hdr    BHDR;
  145. typedef struct memfile        MEMFILE;
  146. typedef long                blocknr_t;
  147.  
  148. /*
  149.  * for each (previously) used block in the memfile there is one block header.
  150.  * 
  151.  * The block may be linked in the used list OR in the free list.
  152.  * The used blocks are also kept in hash lists.
  153.  *
  154.  * The used list is a doubly linked list, most recently used block first.
  155.  *         The blocks in the used list have a block of memory allocated.
  156.  *        mf_used_count is the number of pages in the used list.
  157.  * The hash lists are used to quickly find a block in the used list.
  158.  * The free list is a single linked list, not sorted.
  159.  *        The blocks in the free list have no block of memory allocated and
  160.  *        the contents of the block in the file (if any) is irrelevant.
  161.  */
  162.  
  163. struct block_hdr
  164. {
  165.     BHDR        *bh_next;            /* next block_hdr in free or used list */
  166.     BHDR        *bh_prev;            /* previous block_hdr in used list */
  167.     BHDR        *bh_hash_next;        /* next block_hdr in hash list */
  168.     BHDR        *bh_hash_prev;        /* previous block_hdr in hash list */
  169.     blocknr_t    bh_bnum;                /* block number */
  170.     char_u        *bh_data;            /* pointer to memory (for used block) */
  171.     int            bh_page_count;        /* number of pages in this block */
  172.  
  173. #define BH_DIRTY    1
  174. #define BH_LOCKED    2
  175.     char        bh_flags;            /* BH_DIRTY or BH_LOCKED */
  176. };
  177.  
  178. /*
  179.  * when a block with a negative number is flushed to the file, it gets
  180.  * a positive number. Because the reference to the block is still the negative
  181.  * number, we remember the translation to the new positive number in the
  182.  * double linked trans lists. The structure is the same as the hash lists.
  183.  */
  184. typedef struct nr_trans NR_TRANS;
  185.  
  186. struct nr_trans
  187. {
  188.     NR_TRANS    *nt_next;            /* next nr_trans in hash list */
  189.     NR_TRANS    *nt_prev;            /* previous nr_trans in hash list */
  190.     blocknr_t    nt_old_bnum;            /* old, negative, number */
  191.     blocknr_t    nt_new_bnum;            /* new, positive, number */
  192. };
  193.  
  194. /*
  195.  * Simplistic hashing scheme to quickly locate the blocks in the used list.
  196.  * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
  197.  */
  198. #define MEMHASHSIZE        64
  199. #define MEMHASH(nr)        ((nr) & (MEMHASHSIZE - 1))
  200.  
  201. struct memfile
  202. {
  203.     char_u        *mf_fname;            /* name of the file */
  204.     char_u        *mf_xfname;            /* idem, full path */
  205.     int            mf_fd;                /* file descriptor */
  206.     BHDR        *mf_free_first;        /* first block_hdr in free list */
  207.     BHDR        *mf_used_first;        /* mru block_hdr in used list */
  208.     BHDR        *mf_used_last;        /* lru block_hdr in used list */
  209.     unsigned    mf_used_count;        /* number of pages in used list */
  210.     unsigned    mf_used_count_max;    /* maximum number of pages in memory */
  211.     BHDR        *mf_hash[MEMHASHSIZE];    /* array of hash lists */
  212.     NR_TRANS    *mf_trans[MEMHASHSIZE];    /* array of trans lists */
  213.     blocknr_t    mf_blocknr_max;        /* highest positive block number + 1*/
  214.     blocknr_t    mf_blocknr_min;        /* lowest negative block number - 1 */
  215.     blocknr_t    mf_neg_count;        /* number of negative blocks numbers */
  216.     blocknr_t    mf_infile_count;    /* number of pages in the file */
  217.     unsigned    mf_page_size;        /* number of bytes in a page */
  218.     int            mf_dirty;            /* Set to TRUE if there are dirty blocks */
  219. };
  220.  
  221. /*
  222.  * things used in memline.c
  223.  */
  224. typedef struct info_pointer        IPTR;        /* block/index pair */
  225.  
  226. /*
  227.  * When searching for a specific line, we remember what blocks in the tree
  228.  * are the branches leading to that block. This is stored in ml_stack.
  229.  * Each entry is a pointer to info in a block (may be data block or pointer block)
  230.  */
  231. struct info_pointer
  232. {
  233.     blocknr_t    ip_bnum;        /* block number */
  234.     linenr_t    ip_low;            /* lowest lnum in this block */
  235.     linenr_t    ip_high;        /* highest lnum in this block */
  236.     int            ip_index;        /* index for block with current lnum */
  237. };
  238.  
  239. typedef struct memline MEMLINE;
  240.  
  241. /*
  242.  * the memline structure holds all the information about a memline
  243.  */
  244. struct memline
  245. {
  246.     linenr_t    ml_line_count;    /* number of lines in the buffer */
  247.  
  248.     MEMFILE        *ml_mfp;        /* pointer to associated memfile */
  249.  
  250. #define ML_EMPTY        1        /* empty buffer (one empty line */
  251. #define ML_LINE_DIRTY    2        /* cached line was changed and allocated */
  252. #define ML_LOCKED_DIRTY    4        /* ml_locked was changed */
  253. #define ML_LOCKED_POS    8        /* ml_locked needs positive block number */
  254.     int            ml_flags;
  255.  
  256.     IPTR        *ml_stack;        /* stack of pointer blocks (array of IPTRs) */
  257.     int            ml_stack_top;    /* current top if ml_stack */
  258.     int            ml_stack_size;    /* total number of entries in ml_stack */
  259.  
  260.     linenr_t    ml_line_lnum;    /* line number of cached line, 0 if not valid */
  261.     char_u        *ml_line_ptr;    /* pointer to cached line */
  262.  
  263.     BHDR        *ml_locked;        /* block used by last ml_get */
  264.     linenr_t    ml_locked_low;    /* first line in ml_locked */
  265.     linenr_t    ml_locked_high;    /* last line in ml_locked */
  266.     int            ml_locked_lineadd;    /* number of lines inserted in ml_locked */
  267. };
  268.  
  269. /*
  270.  * buffer: structure that holds information about one file
  271.  *
  272.  * Several windows can share a single Buffer
  273.  * A buffer is unallocated if there is no memfile for it.
  274.  * A buffer is new if the associated file has never been loaded yet.
  275.  */
  276.  
  277. typedef struct buffer BUF;
  278.  
  279. struct buffer
  280. {
  281.     MEMLINE             b_ml;                /* associated memline (also contains
  282.                                          * line count) */
  283.  
  284.     BUF                *b_next;            /* links in list of buffers */
  285.     BUF                *b_prev;
  286.  
  287.     int                 b_changed;            /* Set to 1 if something in the file has
  288.                                           * been changed and not written out. */
  289.  
  290.     int                 b_notedited;        /* Set to TRUE when file name is
  291.                                          * changed after starting to edit, 
  292.                                           * reset when file is written out. */
  293.  
  294.     int              b_nwindows;        /* nr of windows open on this buffer */
  295.  
  296.     int                 b_neverloaded;        /* file has never been loaded into
  297.                                          * buffer, many variables still need
  298.                                          * to be set */
  299.  
  300.     /*
  301.      * b_filename has the full path of the file.
  302.      * b_sfilename is the name as the user typed it.
  303.      * b_xfilename is the same as b_sfilename, unless did_cd is set, then it
  304.      *               is the same as b_filename.
  305.      */
  306.     char_u            *b_filename;
  307.     char_u            *b_sfilename;
  308.     char_u            *b_xfilename;
  309.  
  310.     int                 b_fnum;            /* file number for this file. */
  311.     WINLNUM            *b_winlnum;            /* list of last used lnum for
  312.                                          * each window */
  313.  
  314.     long             b_mtime;            /* last change time of original file */
  315.  
  316.     /*
  317.      * The following only used in mark.c.
  318.      */
  319.     FPOS               b_namedm[NMARKS];    /* current marks */
  320.  
  321.     /*
  322.      * start and end of an operator, also used for '[ and ']
  323.      */
  324.     FPOS             b_startop;
  325.     FPOS             b_endop;
  326.  
  327.     /*
  328.      * The following only used in undo.c.
  329.      */
  330.     struct u_header    *b_u_oldhead;        /* pointer to oldest header */
  331.     struct u_header    *b_u_newhead;        /* pointer to newest header */
  332.     struct u_header    *b_u_curhead;        /* pointer to current header */
  333.     int                 b_u_numhead;        /* current number of headers */
  334.     int                 b_u_synced;        /* entry lists are synced */
  335.  
  336.     /*
  337.      * variables for "U" command in undo.c
  338.      */
  339.     char_u            *b_u_line_ptr;        /* saved line for "U" command */
  340.     linenr_t         b_u_line_lnum;        /* line number of line in u_line */
  341.     colnr_t             b_u_line_colnr;    /* optional column number */
  342.  
  343.     /*
  344.      * The following only used in undo.c
  345.      */
  346.     struct m_block     b_block_head;        /* head of allocated memory block list */
  347.     info_t            *b_m_search;         /* pointer to chunk before previously
  348.                                             * allocated/freed chunk */
  349.     struct m_block    *b_mb_current;        /* block where m_search points in */
  350.  
  351.     /*
  352.      * Variables "local" to a buffer.
  353.      * They are here because their value depends on the type of file
  354.      * or contents of the file being edited.
  355.      * The "save" options are for when the paste option is set.
  356.      */
  357.     int                 b_p_ai, b_p_si, b_p_ro;
  358.     int                 b_p_bin, b_p_eol, b_p_et, b_p_ml, b_p_sn, b_p_tx;
  359.     long             b_p_sw, b_p_ts, b_p_tw, b_p_wm;
  360.     int                 b_p_ai_save, b_p_si_save;
  361.     long             b_p_tw_save, b_p_wm_save;
  362.  
  363.     char             b_did_warn;        /* Set to 1 if user has been warned on
  364.                                          * first change of a read-only file */
  365.  
  366. #ifndef MSDOS
  367.     int                 b_shortname;        /* this file has an 8.3 filename */
  368. #endif
  369. };
  370.  
  371. /*
  372.  * Structure which contains all information that belongs to a window
  373.  *
  374.  * All row numbers are relative to the start of the window, except w_winpos.
  375.  */
  376.  
  377. struct window
  378. {
  379.     BUF            *w_buffer;             /* buffer we are a window into */
  380.  
  381.     WIN            *w_prev;            /* link to previous window (above) */
  382.     WIN            *w_next;            /* link to next window (below) */
  383.  
  384.     FPOS        w_cursor;            /* cursor's position in buffer */
  385.  
  386.     /*
  387.      * These elements are related to the cursor's position in the window.
  388.      * This is related to character positions in the window, not in the file.
  389.      */
  390.     int            w_row, w_col;        /* cursor's position in window */
  391.  
  392.     colnr_t        w_virtcol;            /* column number of the file's actual */
  393.                                     /* line, as opposed to the column */
  394.                                     /* number we're at on the screen. */
  395.                                     /* This makes a difference on lines */
  396.                                     /* which span more than one screen */
  397.                                     /* line. */
  398.  
  399.     colnr_t        w_curswant;            /* The column we'd like to be at. */
  400.                                     /* This is used to try to stay in */
  401.                                     /* the same column through up/down */
  402.                                     /* cursor motions. */
  403.  
  404.     int            w_set_curswant;        /* If set, then update w_curswant */
  405.                                     /* the next time through cursupdate() */
  406.                                     /* to the current virtual column */
  407.  
  408.     linenr_t    w_topline;            /* number of the line at the top of
  409.                                      * the screen */
  410.     linenr_t    w_botline;            /* number of the line below the bottom
  411.                                      * of the screen */
  412.     int            w_empty_rows;        /* number of ~ rows in window */
  413.  
  414.     int            w_winpos;            /* row of topline of window in screen */
  415.     int            w_height;            /* number of rows in window, excluding
  416.                                         status/command line */
  417.     int            w_status_height;    /* number of status lines (0 or 1) */
  418.  
  419.     int            w_redr_status;        /* if TRUE status line must be redrawn */
  420.     int            w_redr_type;        /* type of redraw to be performed on win */
  421.  
  422.     int            w_leftcol;            /* starting column of the screen */
  423.  
  424. /*
  425.  * The height of the lines currently in the window is remembered
  426.  * to avoid recomputing it every time. The number of entries is w_nrows.
  427.  */
  428.     int             w_lsize_valid;        /* nr. of valid LineSizes */
  429.     linenr_t     *w_lsize_lnum;        /* array of line numbers for w_lsize */
  430.     char_u          *w_lsize;            /* array of line heights */
  431.  
  432.     int            w_alt_fnum;            /* alternate file (for # and CTRL-^) */
  433.  
  434.     int            w_arg_idx;            /* current index in argument list */
  435.  
  436.     /*
  437.      * Variables "local" to a window.
  438.      * They are here because they influence the layout of the window or
  439.      * depend on the window layout.
  440.      */
  441.     int            w_p_list,
  442.                 w_p_nu,
  443.                 w_p_wrap;
  444.     long        w_p_scroll;
  445.  
  446.     /*
  447.      * The w_prev_pcmark field is used to check whether we really did jump to
  448.      * a new line after setting the w_pcmark.  If not, then we revert to
  449.      * using the previous w_pcmark.
  450.      */
  451.     FPOS        w_pcmark;            /* previous context mark */
  452.     FPOS        w_prev_pcmark;        /* previous w_pcmark */
  453.  
  454.     /*
  455.      * the jumplist contains old cursor positions
  456.      */
  457.     struct filemark w_jumplist[JUMPLISTSIZE];
  458.     int             w_jumplistlen;    /* number of active entries */
  459.     int                w_jumplistidx;    /* current position */
  460.  
  461.     /*
  462.      * the tagstack grows from 0 upwards:
  463.      * entry 0: older
  464.      * entry 1: newer
  465.      * entry 2: newest
  466.      */
  467.     struct taggy    w_tagstack[TAGSTACKSIZE];    /* the tag stack */
  468.     int                w_tagstackidx;                /* index just below active entry */
  469.     int                w_tagstacklen;                /* number of tags on the stack */
  470.  
  471. };
  472.